package com.dq.health.controller;

import com.dq.health.dto.response.menu.SysMenuTreeInfo;
import com.dq.health.entity.menu.SysMenu;
import com.dq.health.service.IAPIMenuService;
import com.dq.health.utils.data.Tree;
import com.dq.health.utils.view.SimpleView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu")
@Api(tags = "菜单管理")
public class MenuController {
    private @Autowired IAPIMenuService menuService;

    @PostMapping(value = "/getAllSysMenu")
    @ApiOperation("获取所有菜单权限")
    public SimpleView<Tree<SysMenuTreeInfo>> getAllSysMenu() {
        SimpleView<Tree<SysMenuTreeInfo>> view = new SimpleView<>();

        List<SysMenu> menus = menuService.selectMenuList();
        view.success(menuService.buildMenus(menus));

        return view;
    }
}
